package com.sc.servlet.user.comment;

import com.alibaba.fastjson.JSON;
import com.sc.pojo.Comment;
import com.sc.services.UserServices;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @description: 根据userid查找所有评论
 * @author: sc
 * @create: 2023-01-05 02:12
 **/
@WebServlet("/selectMyCommentById")
public class selectMyCommentByIdServlet extends HttpServlet {

    private UserServices userServices = new UserServices();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String userid = request.getParameter("userid");
        List<Comment> comments = userServices.selectCommentByUserId(userid);


        String jsonString = JSON.toJSONString(comments);
        System.out.println(jsonString);
        //3. 写数据
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonString);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}